package com.gem.eolane.service;

import com.gem.eolane.entity.Demo;
import com.gem.eolane.entity.PcbOffer;
import com.gem.eolane.mapper.BackstaMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BackstaService {
    public static Integer CURRENT_PAGE = 1;
    public static Integer PAGE_SIZE = 4;


    @Autowired
    private BackstaMapper backstaMapper;

    //从数据库读取数据显示在pcb订单
    public List<Demo> demos(Integer page, Integer size){
        if (page != null) {
            CURRENT_PAGE = page;
        }
        if (size != null) {
            PAGE_SIZE = size;
        }
        CURRENT_PAGE=(CURRENT_PAGE-1)*PAGE_SIZE;
        return backstaMapper.demo(CURRENT_PAGE,PAGE_SIZE);
    }

    //获取pcb订单总数
    public int count(){
        return backstaMapper.count();
    }



    //从数据库读取数据显示在历史订单
    public List<Demo> listro(Integer page, Integer size){
        if (page != null) {
            CURRENT_PAGE = page;
        }
        if (size != null) {
            PAGE_SIZE = size;
        }
        CURRENT_PAGE=(CURRENT_PAGE-1)*PAGE_SIZE;
        return backstaMapper.listro(CURRENT_PAGE,PAGE_SIZE);
    }

    //查询订单总数
    public int listroCount(){
        return backstaMapper.listroCount();
    }


    //从数据库读取数据进入历史订单详情页面
    public List<PcbOffer> findPcbList(String id) {
        List<PcbOffer> list = backstaMapper.findPcbList(id);
        return list;
    }

    //批量删除数据
    public void listdelreues(List<Integer> list){
        backstaMapper.listdelreues(list);
    }


    //根据訂單編號查询返回到pcb订单页面
    public List<Demo> findbyoid(String IdCard){
       List<Demo> list = backstaMapper.findbyoid(IdCard);
       return list;
    }
    //根据公司名称查询返回到pcb订单页面
    public List<Demo> findComp(String company,Integer page, Integer size){
        if (page != null) {
            CURRENT_PAGE = page;
        }
        if (size != null) {
            PAGE_SIZE = size;
        }
        CURRENT_PAGE=(CURRENT_PAGE-1)*PAGE_SIZE;
       List<Demo> list = backstaMapper.findComp(company,CURRENT_PAGE,PAGE_SIZE);
       return list;
    }

    //查询公司所有訂單总数
    public int Comcount(String company){
        return backstaMapper.Comcount(company);
    }
}